import Vue from 'vue'
import VueRouter from 'vue-router'
// import HomeView from '../views/HomeView.vue'


// @代表src目录全局
import Login from '@/components/Login.vue'
import Register from '@/components/Register.vue'

Vue.use(VueRouter)

const routes = [
  // 重定向
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
    name: 'login',
    component: Login, // 刚刚引入的组件
    meta: {
      title: "登录"
    }
  },
  {
    path: '/register',
    name: 'register',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    // component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
    component: Register,
    meta: {
      title: "注册"
    }
  }
]

// 创建路由规则
const router = new VueRouter({
  routes,
  mode: 'history',
  linkActiveClass: 'my_active',
  linkExactActiveClass: 'my_exact_active'
})

// 全局路由钩子函数
router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})



export default router
